#ifndef INTERPRETER_H
#define INTERPRETER_H
#include "common.h"
#include "byte_code.h"

#ifdef TAG
#undef TAG
#endif
#define TAG "INTERPRETER "

class ValPool
{
public:
    ValPool(int size = 0)
    {
        size_ = size;
        pool_ = new int[size_];
    }
    virtual ~ValPool()
    {
        delete [] pool_;
    }
    void SetValue(int pos, int val)
    {
        if (pos < size_) {
            pool_[pos] = val;
        }
    }
    int GetValue(int pos)
    {
        if (pos < size_) {
            return pool_[pos];
        }
    }
    void Print()
    {
        cout << "Register value:" << endl;
        for (int i = 0; i < size_; i++) {
            cout << "Reg v" << i << ": " << pool_[i] << endl;
        }
    }

private:
    int size_;
    int* pool_;
};

class Interpreter
{
public:
    Interpreter(string input = DEFAULT_OUTPUT_FILE);
    virtual ~Interpreter();
    bool CheckAndResolve();
    void Interpret();

private:
    string input_file_name_;
    ifstream fin_;
    ValPool* reg_pool_;
    inline int GetOpValue(string s)
    {
        const char* temp = s.c_str();
        temp++;
        int ans = atoi(temp);
        return ans;
    }
};
#endif // INTERPRETER_H